import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store/index'
const InforList = () => import('../components/List/InforList')
const Myself = () => import('../views/Myself/MySelf')
const Forum = () => import('../views/Forum/Forum')
const Introduction = () => import('../views/Introduction/Introduction')
const HeroList = () => import('../components/List/HeroList')
const InscList = () => import('../components/List/InscList')
const ItemList = () => import('../components/List/ItemList')
const SkillList = () => import('../components/List/SkillList')
const Login = () => import('../views/Myself/Login')
const Nav = () => import('../views/Nav')
const IDLogin = () => import('../components/Login/IDLogin')
const EmailLogin = () => import('../components/Login/EmailLogin')
const Register = () => import('../components/Login/Register')
const Modify = () => import('../views/Myself/Modify')
const Invitation = () => import('../views/Forum/Invitation')
const CreateInvi = () => import('../views/Forum/CreateInvi')
const Like = () => import('../views/Myself/Like')
const Send = () => import('../views/Myself/Send')
const Star = () => import('../views/Myself/Star')
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Nav,
    redirect: '/introduction',
    children: [{
      path: '/introduction',
      redirect: '/introduction/Information',
      component: Introduction,
      children: [
        {
          path: '/introduction/Hero',
          component: HeroList
        }, {
          path: '/introduction/Insc',
          component: InscList
        },
        {
          path: '/introduction/Skill',
          component: SkillList
        },
        {
          path: '/introduction/Item',
          component: ItemList
        }, {
          path: '/introduction/Information',
          component: InforList
        }
      ]
    },
    {
      path: '/forum',
      component: Forum
    },
    {
      path: '/myself',
      component: Myself
    }]
  },
  {
    path: '/login',
    component: Login,
    redirect: '/login/id',
    children: [{
      path: '/login/id',
      component: IDLogin
    },
    {
      path: '/login/email',
      component: EmailLogin
    },
    {
      path: '/login/register',
      component: Register
    }]
  },
  {
    path: '/modify/:id',
    component: Modify,
    props: true
  },
  {
    path: '/Invi/:id',
    component: Invitation,
    props: true

  }, {
    path: '/CreateInvi',
    component: CreateInvi
  }, {
    path: '/like',
    component: Like
  }, {
    path: '/star',
    component: Star
  }, {
    path: '/send',
    component: Send
  }
]
const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (from.path === '/like' || from.path === '/star' || from.path === '/send') {
    window.sessionStorage.setItem('nextpath', from.path)
  } else {
    window.sessionStorage.removeItem('nextpath')
  }
  if (to.path === '/CreateInvi') {
    if (store.state.User.LoginStatus) {
      return next()
    } else {
      return Vue.prototype.$toast.fail('请先登录')
    }
  }
  next()
})

export default router
